package br.ita.battlefarm.moves;

import br.ita.battlefarm.R;
import br.ita.battlefarm.core.Board;

public class XMove extends Move {

	public XMove(){
		_allowedMoves = 1;
		_backgroundRes = R.drawable.shot_x;
		disableMove();
	}

	@Override
	public int fire(Board board, int i, int j) {
		int changeInScore = 0;
		if(hasMovesLeft()){
			if( board.validPlayPosition(i,j) ){
				_allowedMoves--;
				for(int line = i; line < board.getNumRows(); line++){
					changeInScore += fireInSquare(board, line, j + line - i);
				}
				for(int line = i; line < board.getNumRows(); line++){
					changeInScore += fireInSquare(board, line, j - line + i);
				}
				for(int line = i; line >= 0; line--){
					changeInScore += fireInSquare(board, line, j + line - i);
				}
				for(int line = i; line >= 0; line--){
					for(int column = j; column >= 0; column--){
						changeInScore += fireInSquare(board, line, j - line + i);
					}
				}
				if(!hasMovesLeft()){
					disableMove();
				}
			}
		}
		return changeInScore;
	}

	

}
